package o;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.os.Process;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.System;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

public class cyh {
    public static int ˋ(Context context, String str) {
        return context.checkPermission(str, Process.myPid(), Process.myUid());
    }

    public static void ˎ(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                cyk.ˏ.ˏ("Utils", "Exception when closing the closeable.");
            }
        }
    }

    public static int ˏ(Intent intent, String str, int i) {
        try {
            i = intent.getIntExtra(str, i);
        } catch (Exception e) {
            cyk.ˏ.ˏ("Utils", "Exception when retrieving extended data from the intent, exception: " + e);
        }
        return i;
    }

    public static String ˎ(Intent intent, String str) {
        try {
            return intent.getStringExtra(str);
        } catch (Exception e) {
            cyk.ˏ.ˏ("Utils", "Exception when retrieving extended data from the intent, exception: " + e);
            return null;
        }
    }

    public static String ॱ(Context context) {
        String str = null;
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.HOME");
        PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            return null;
        }
        ResolveInfo resolveActivity = packageManager.resolveActivity(intent, 0);
        if (resolveActivity == null || resolveActivity.activityInfo == null || "android".equals(resolveActivity.activityInfo.packageName)) {
            return null;
        }
        CharSequence charSequence = resolveActivity.activityInfo.packageName;
        List<ResolveInfo> queryIntentActivities = packageManager.queryIntentActivities(intent, 0);
        if (queryIntentActivities.isEmpty()) {
            return null;
        }
        for (ResolveInfo resolveInfo : queryIntentActivities) {
            if (TextUtils.equals(charSequence, resolveInfo.activityInfo.packageName)) {
                return charSequence;
            }
            String str2;
            if (str == null) {
                str2 = resolveInfo.activityInfo.packageName;
            } else {
                str2 = str;
            }
            str = str2;
        }
        return str;
    }

    public static int ˊ(@NonNull Context context) {
        PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            return 0;
        }
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            if (packageInfo != null) {
                return packageInfo.versionCode;
            }
            return 0;
        } catch (NameNotFoundException e) {
            return 0;
        }
    }

    public static int ˎ(Context context) {
        return ˋ(context, 1);
    }

    private static int ˋ(Context context, int i) {
        try {
            i = System.getInt(context.getContentResolver(), "simpleui_mode");
        } catch (SettingNotFoundException e) {
        } catch (Exception e2) {
        }
        return i;
    }

    public static String ˋ(String str) {
        return str == null ? "" : str;
    }

    public static String ˊ(String str) {
        return str == null ? "" : str.toUpperCase(Locale.getDefault());
    }
}
